﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Engine.Utils.Contants;
using Microsoft.Xna.Framework;

namespace Engine.SceneControl.Scene.PostEffects
{
    public class WiggleShading : IPostEffect
    {
        private Effect wiggle;
        private float m_Timer = 0;
        private SpriteBatch spriteBatch;

        #region IPostEffect Members

        public void Draw(IRenderHelper rHelper, Engine.SceneControl.Scene.DefRender.QuadRender render,GameTime gt,Rectangle sr)
        {

            m_Timer += (float)gt.ElapsedGameTime.Milliseconds / 500;

            spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            {
                // Apply the post process shader
                wiggle.Begin();
                {
                    wiggle.CurrentTechnique.Passes[0].Begin();
                    {
                        wiggle.Parameters["fTimer"].SetValue(m_Timer);
                        spriteBatch.Draw(rHelper[PrincipalConstants.CurrentImage], sr, Color.White);
                        wiggle.CurrentTechnique.Passes[0].End();
                    }
                }
                wiggle.End();
            }
            spriteBatch.End();
            
        }

        #endregion

        #region IPostEffect Members
        EngineStuff engine;
        public void init(EngineStuff engine)
        {
            this.engine = engine;
            this.wiggle = engine.Content.Load<Effect>("..\\Content\\Effects\\Deferred\\wiggle");
            spriteBatch = engine.SpriteBatch;
        }

        #endregion
    }
}
